import React from 'react';
import { useDispatch } from 'react-redux';
import * as counterReducer from '../redux/counter/action.js';
import * as userReducer from '../redux/user/action.js';



export default function CounterAction() {
  // 使用 useDispatch 获取 dispatch 函数
  const dispatch = useDispatch();

  // 定义增加、减少和重置计数的函数
  const increment = () => {
    dispatch(counterReducer.increment(2));
  };

  const decrement = () => {
    dispatch(counterReducer.decrement(1));
  };

  const reset = () => {
    dispatch(counterReducer.reset());
  };

  const updateUserName = () => {
    // 这里可以添加更新用户名的逻辑
    dispatch(userReducer.updateUserName('李四'));
  };

  return (
    <>
      <div>
        <button onClick={increment}>+</button>
        <button onClick={decrement}>-</button>
        <button onClick={reset}>Reset</button>
      </div>
      <div style={{ marginTop: '20px' }}>
        <button onClick={updateUserName}>修改用户名</button>
      </div>
    </>
  );
}